from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

wd = webdriver.Edge("msedgedriver")
wd.implicitly_wait(10)
wd.get("https://www.bv2008.cn/app/user/register.php?type=org")

wd.find_element(By.ID, 'login_name').send_keys('abcde123')

wd.find_element(By.CSS_SELECTOR, '#reg_org > table > tbody:nth-child(1) > tr:nth-child(10) >'
                                 ' td:nth-child(2) > input[type=radio]:nth-child(2)').click()

# Select(wd.find_element(By.ID, 'org_type1')).select_by_value('1727')
Select(wd.find_element(By.ID, 'org_type1')).select_by_visible_text('社会服务机构')

wd.find_element(By.CSS_SELECTOR, '#org_record1 > tr:nth-child(2) > td:nth-child(2) > a').click()
wd.switch_to.frame(wd.find_element(By.CSS_SELECTOR, 'body > div.div_tips > iframe'))
wd.find_element(By.CSS_SELECTOR, '#org_list > ul > li > span.son > ul > li:nth-child(1) > a:nth-child(3)').click()
wd.switch_to.default_content()

wd.find_element(By.CSS_SELECTOR, 'body > div.nav > div > a:nth-child(2)').click()
wd.find_element(By.CSS_SELECTOR, 'body > div.main > div:nth-child(1) > ul > li:nth-child(2) > div > a').click()

for window_handle in wd.window_handles:
    wd.switch_to.window(window_handle)
    if '助力' in wd.title:
        break

wd.find_element(By.CSS_SELECTOR, '#main_body > div.wrap.clearfix.m10 > div.conr >'
                                 ' div:nth-child(2) > table > tbody > tr > td:nth-child(2) > a').click()
# wd.quit()
